import {createSlice} from '@reduxjs/toolkit';
const cartSlice = createSlice({
    // 模块名称
    name:'cart',
    // 状态数据初始值
    initialState:{
        cartList:[
            {
                id:1,
                goodsid:1,
                goodsname:'特斯拉',
                price:300000,
                num:1
            },
            {
                id:2,
                goodsid:2,
                goodsname:'岚图',
                price:270000,
                num:2
            },
            {
                id:3,
                goodsid:3,
                goodsname:'问界',
                price:270000,
                num:10
            }
        ]
    },
    // 更新状态数据的方法
    reducers:{
        // state:系统参数
        // payload : 待删除的商品索引
        cartDel(state,payload){
            state.cartList.splice(payload,1);
        }
    }
});
// 导出actionCreator
export const {cartDel}=cartSlice.actions;
// 导入reducer函数
export default cartSlice.reducer;